package main

import (
	"fmt"
)

func main() {
	var arr1 = [5]int{1, 2, 3, 4, 5}
	var s = arr1[2:]
	fmt.Printf("arr1 : %p slice:%p\n", &arr1[2], s)

	var arr2 = [10]int{}
	var s2 = arr2[:]
	fmt.Printf("slice %p len:%d\n", s2, len(s2))
	s2 = append(s2, 2)
	fmt.Printf("slice %p len: %d(should change)\n", s2, len(s2))
	s2 = append(s2, s2[:len(s2)-2]...)
	fmt.Printf("slice: %p len: %d(should not change)\n", s2, len(s2))
	s2 = append(s2, 1)
	fmt.Printf("slice: %p len: %d(should change)\n", s2, len(s2))

	var arr3 = [10]int{8: 2}
	var s3 = arr3[:8]
	fmt.Printf("slice %p len: %d\n", s3, len(s3))
	fmt.Printf("array %v\n\n", arr3)
	s3 = append(s3, 2)
	fmt.Printf("slice %p len %d(should not change)\n", s3, len(s3))
	fmt.Printf("arr3: %v\n\n", arr3)
	s3 = append(s3, 2)
	fmt.Printf("slice %p len %d(should not change)\n", s3, len(s3))
	fmt.Printf("arr3: %v\n\n", arr3)
	s3 = append(s3, 2)
	fmt.Printf("slice %p len %d(should change)\n", s3, len(s3))
	fmt.Printf("arr3: %v\n\n", arr3)

	// slice copy
	s4 := []int{1, 2, 3, 4, 5}
	s5 := make([]int, 3, 4)
	fmt.Printf("s5:%v, s4:%v\n", s5, s4)
	copy(s5, s4)
	fmt.Printf("s5:%v, cap:%d, prt:%p\n", s5, cap(s5), s5)
	s5 = append(s5, 1)
	fmt.Printf("s5:%v, cap:%d,prt:%p\n", s5, cap(s5), s5)
	copy(s5, s4)
	fmt.Printf("s5:%v, s4:%v\n", s5, s4)
}
